package com.hujiang.demo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.hujiang.demo.R;
import com.hujiang.demo.core.Calculator;
import com.hujiang.demo.core.activity.SDKActivity;
import com.hujiang.demo.utils.Config;

import java.util.ArrayList;

public class HelloAndroidActivity extends Activity {

    private static String TAG = "HelloAndroidActivity";

    private TextView txtEnv;
    private Button btnSum;
    private Button btnNext;
    private Button btnJoin;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtEnv = (TextView) findViewById(R.id.txtEnv);
        btnSum = (Button) findViewById(R.id.btnSum);
        btnJoin = (Button) findViewById(R.id.btnJoin);
        btnNext = (Button) findViewById(R.id.btnNext);

        init();
    }

    private void init() {
        txtEnv.setText(Config.getInstance(this).getEnvName());

        btnSum.setOnClickListener(clickListener);

        btnJoin.setOnClickListener(joinListener);

        btnNext.setOnClickListener(nextListener);
    }

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calculator calculator = new Calculator();
            int t = calculator.getOneToHundred();

            Log.d(TAG, "result:" + t);

            Toast.makeText(HelloAndroidActivity.this, "result: " + t, Toast.LENGTH_LONG).show();
        }
    };

    View.OnClickListener joinListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ArrayList<String> list = new ArrayList<String>();
            list.add("maven");
            list.add("abc");

            //common-1.0
            com.hujiang.utils.StringUtil.sayHello();

            //common-2.0
            String res = com.hujiang.utils.StringUtil.join(list, "_");
            //String res = StringUtil.join(list);

            Toast.makeText(HelloAndroidActivity.this, "result: " + res, Toast.LENGTH_LONG).show();
        }
    };
    View.OnClickListener nextListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(HelloAndroidActivity.this, SDKActivity.class);
            startActivity(intent);
        }
    };
}

